//
//  JuAllorientationViewController.m
//  JuInterfaceRotation
//
//  Created by Juvid on 2017/6/15.
//  Copyright © 2017年 Juvid. All rights reserved.
//

#import "JuAllorientationViewController.h"

@interface JuAllorientationViewController ()

@end

@implementation JuAllorientationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
     [self juSetOrientation];
    // Do any additional setup after loading the view.
}
/**
 强制横屏
 */
-(void)juSetOrientation{
    
    //    if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
    //         [[UIDevice currentDevice] performSelector:@selector(setOrientation:) withObject:@(UIDeviceOrientationPortrait)];
    //    }
    
    SEL selector = NSSelectorFromString(@"setOrientation:");
    NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
    [invocation setSelector:selector];
    [invocation setTarget:[UIDevice currentDevice]];
    int val = UIDeviceOrientationLandscapeLeft;
    [invocation setArgument:&val atIndex:2];//前两个参数已被target和selector占用
    [invocation invoke];
    
}

/**
 获取设备方向
 */
-(void)juGetOrientation{
    UIDevice *device = [UIDevice currentDevice];
    switch (device.orientation) {
        case UIDeviceOrientationUnknown:
            NSLog(@"Unknown");
            break;
            
        case UIDeviceOrientationFaceUp:
            NSLog(@"Device oriented flat, face up");
            break;
            
        case UIDeviceOrientationFaceDown:
            NSLog(@"Device oriented flat, face down");
            break;
            
        case UIDeviceOrientationLandscapeLeft:
            NSLog(@"Device oriented horizontally, home button on the right");
            break;
            
        case UIDeviceOrientationLandscapeRight:
            NSLog(@"Device oriented horizontally, home button on the left");
            break;
            
        case UIDeviceOrientationPortrait:
            NSLog(@"Device oriented vertically, home button on the bottom");
            break;
            
        case UIDeviceOrientationPortraitUpsideDown:
            NSLog(@"Device oriented vertically, home button on the top");
            break;
            
        default:
            NSLog(@"cannot distinguish");
            break;
    }
}
- (BOOL)shouldAutorotate{
    return YES;
}
-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscapeLeft;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
